package config.ioc;

import com.dao.UserDao;
import com.dao.UserDaoImpl;
import com.service.UserService;
import com.service.UserServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HelloIocConfig2 {


    //2.类似于以前的构造函数注入，
    // 只要在bean方法的参数里添加所依赖的类型即可
    @Bean
    public UserService userService(UserDao dao) {
        //context.getBean(UserDao.class);
        UserServiceImpl userService = new UserServiceImpl();
        userService.setDao(dao);
        return userService;
    }

    @Bean
    public UserDao userDao() {
        return new UserDaoImpl();
    }
}
